package com.javaspeak.concurrency.pattern.actor;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.internal.TextListener;
import org.junit.runner.JUnitCore;

import com.javaspeak.concurrency.pattern.actor.ActorRegistry;
import com.javaspeak.concurrency.pattern.actor.ActorRegistryImpl;
import com.javaspeak.concurrency.pattern.application.UtilityActor;
import com.javaspeak.concurrency.pattern.application.UtilityActorImpl;

/**
 * @author John Dickerson
 */
public class UtilityActorTest {

    public Logger logger = Logger.getLogger( UtilityActorTest.class );

    @Test
    public  void testUtilityactor(){

        ActorRegistry actorRegistry = ActorRegistryImpl.getInstance();
        actorRegistry.registerActor( new UtilityActorImpl() );

        UtilityActor utilityActor =
            ( UtilityActor )actorRegistry.getActor(
                    UtilityActor.class );

        String text = "actor pattern";

        String title =
            utilityActor.convertToUpperCase( text );

        logger.debug( title );

        actorRegistry.shutDown();

        org.junit.Assert.assertEquals(text.toUpperCase(), title );
    }


    public static void main( String args[] ){

        BasicConfigurator.resetConfiguration();
        BasicConfigurator.configure();

        JUnitCore junitCore = new JUnitCore();
        junitCore.addListener( new TextListener( System.out ) );
        junitCore.run( UtilityActorTest.class );
    }
}
